package cn.imnaer.service.rpc.scenic.dao;

import java.util.ArrayList;
import java.util.List;

import org.bson.BSONObject;
import org.bson.BasicBSONObject;

import cn.imnaer.common.factory.TimeHelper;
import cn.imnaer.database.BaseDao;
import cn.imnaer.database.define.DBConstant;
import cn.imnaer.service.persistence.model.ScenicContribution;
import cn.imnaer.service.persistence.model.consts.SCENICCONTRIBUTION;

public class ScenicContributionDaoImpl extends BaseDao<ScenicContribution> {
	private static ScenicContributionDaoImpl instance = new ScenicContributionDaoImpl();

	private ScenicContributionDaoImpl() {

	}

	public static ScenicContributionDaoImpl getInstance() {
		return instance;
	}

	@Override
	protected String getDbSpaceName() {
		// TODO Auto-generated method stub
		return DBConstant.SPACE.SCENIC_INFO_SPACE;
	}

	@Override
	protected String getDbCollectionName() {
		// TODO Auto-generated method stub
		return DBConstant.COLLECTION.SCENIC_CONTRIBUTION_INFO_COLLECTION;
	}

	@Override
	protected String getPrimaryKey() {
		// TODO Auto-generated method stub
		return SCENICCONTRIBUTION.contributionId;
	}

	@Override
	protected void beforeSave(ScenicContribution obj) {
		// TODO Auto-generated method stub
		super.beforeSave(obj);
		obj.setCreateTime(TimeHelper.getCurrentTime());
	}

	public List<ScenicContribution> getUserContributionsByUserId(String userId) {
		BSONObject query = new BasicBSONObject();
		query.put("userId", userId);
		BSONObject order = new BasicBSONObject();
		order.put("createTime", -1);
		return this.findAll(query, order);
	}
	public List<String> getMyContributScenicsByUserId(String userId) {
		List<String> scenicIds=new ArrayList<>();
List<ScenicContribution> record = this.getUserContributionsByUserId(userId);
for (ScenicContribution scenicContribution : record) {
	scenicIds.add(scenicContribution.getScenicId());
}
return  scenicIds;
	}
}
